<template>
	<view>
		<!-- 页面内容开始 -->

		<!-- 表格组件开始 -->
		<vk-data-table
			ref="table1"
			:action="table1.action"
			:columns="table1.columns"
			:query-form-param="queryForm1"
			:right-btns="['detail_auto']"
			:left-fixed="false"
			:right-fixed="false"
			:selection="false"
			:row-no="true"
			:pagination="true"
			size="mini"
			@current-change="currentChange"
			@selection-change="selectionChange"
		>
			<template  v-slot:calc_rule="{ row, column, index }">
				<view v-if="row.add_type === 4">
					<view>奖励金额：{{ row.calc_rule.calc_amount }}</view>
					<view>扣回奖励：{{ row.calc_rule.reward_value }}</view>
					<view>扣回占比：{{ vk.pubfn.percentageFilter(row.calc_rule.k) }}</view>
				</view>
				<view v-else-if="row.add_type === 4">
					<view>商品金额：{{ row.calc_rule.calc_amount }}</view>
					<view>奖励金额：{{ row.calc_rule.reward_value }}</view>
					<view>奖励占比：{{ vk.pubfn.percentageFilter(row.calc_rule.k) }}</view>
				</view>
			</template>
		</vk-data-table>
		<!-- 表格组件结束 -->

		<!-- 页面内容结束 -->
	</view>
</template>

<script>
var that; // 当前页面对象
var vk = uni.vk;									// vk实例
var addTypeData = vk.getVuex('$app.config.maill.rec.addType');
export default {
	props: {
		orderInfo:{
			Type:Object,
		}
	},
	data: function() {
		// 组件创建时,进行数据初始化
		return {
			// 页面是否请求中或加载中
			loading: false,
			// init请求返回的数据
			data: {},
			// 表格相关开始 -----------------------------------------------------------
			table1:{
				// 表格数据请求地址
				action:"admin/business/sys/salesman.getRewardList",
				// 表格字段显示规则
				columns:[
					{ key: "userInfo.avatar", title: "用户头像", type: "avatar", width: 70, imageWidth:50, shape:"circle" }, // circle 圆形 square 方形
					{ key:"group1", title:"基础信息", type:"group", width:250 ,
						columns:[
							{ key:"userInfo.nickname", title:"用户昵称", type:"text", width:150 },
							{ key:"title", title:"标题", type:"text", width:150 },
							{ key:"comment", title:"备注", type:"text", width:150 },
						]
					},
					{ key:"value", title:"奖励", type:"money", width:100 },
					{
					  key:"is_freeze", title:"状态", type:"tag", width:70, size:"mini", effect:"light",
					  data:[
					    { value:true, label:"冻结", tagType:"danger" },
					    { value:false, label:"正常", tagType:"success" }
					  ]
					},
					{ key:"group2", title:"时间信息", type:"group", width:200 ,
						columns:[
							{ key:"unfreeze_time", title:"解冻时间", type:"time", width:150 },
							{ key:"_add_time", title:"添加时间", type:"time", width:160, sortable:"custom"  },
							{ key:"_add_time", title:"距离现在", type:"dateDiff", width:120 },
						]
					},
					{ key:"reward_type", title:"类型", type:"text", width:90,
						formatter: (val, row, column, index) => {
							if (row.reward_type == 0) return "未分类";
							if (row.reward_type == 1) {
								if (row.reward_type_lv == 1) return "直推奖励";
								if (row.reward_type_lv == 2) return "间推奖励";
							}
							if (row.reward_type == 2) return "区域奖励";
						}
					},
					{ key: "add_type",title: "添加方式",type: "tag",width: 100, size:"small", data:addTypeData },
					{ key:"calc_rule", title:"计算规则", type:"object", width:160,
						columns:[
							{ key:"calc_amount", title:"计算金额", type:"number", width:150, defaultValue:"-" },
							{ key:"reward_value", title:"奖励金额", type:"number", width:150, defaultValue:"-" },
							{ key:"k", title:"奖励比例", type:"percentage", width:150, defaultValue:"-" },
						]
					},
				],
				// 当前高亮的记录
				selectItem:""
			},
			// 表格相关结束 -----------------------------------------------------------
			// 查询表单请求数据
			queryForm1:{
				// 查询表单数据源，可在此设置默认值
				formData:{
					no:""
				},
				// 查询表单的字段规则 fieldName:指定数据库字段名,不填默认等于key
				columns:[
					{ key:"no", title:"订单号", type:"text", width:160, mode:"=", hidden:true },
				]
			},
			// 表单相关结束-----------------------------------------------------------
		};
	},
	created() {
		that = this;
		that.init();
	},
	mounted() {},
	methods: {
		// 初始化
		init() {
			that.queryForm1.formData.no = that.orderInfo.order_no || "___";
		},
		// 页面打开
		pageOpen() {
			that = this;
			let { value, form1 } = that;
			let { item } = value;
		},
		// 页面关闭
		pageClose() {},
		// 页面返回
		pageBack() {
			let { value } = that;
			value.show = false;
			that.$emit("input", value);
		},
		// 搜索
		search() {
			that.$refs.table1.query();
			that.$emit("refresh");
		},
		// 刷新
		refresh() {
			that.$refs.table1.refresh();
			that.$emit("refresh");
		},
		// 获取当前选中的行的数据
		getCurrentRow() {
			return that.$refs.table1.getCurrentRow();
		},
		// 监听 - 行的选中高亮事件
		currentChange(val) {
			that.selectItem = val;
			that.showOneBtn = val ? true : false;
		},
		// 当选择项发生变化时会触发该事件
		selectionChange(list) {
			that.multipleSelection = list;
		}
	},
	// 监听属性
	watch: {},
	// 过滤器
	filters: {},
	// 计算属性
	computed: {}
};
</script>

<style lang="scss" scoped></style>
